package com.zhike.b2b.zhidao.impl;

import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.zhike.b2b.base.BaseService;

@Service
public class ZhidaoInfo extends BaseService
{
  public boolean AddQuestion(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6)
  {
    String str1 = "";
    String str2 = "true";
    if ((paramString1.equals("question")) && (!paramString5.equals("")))
      str1 = "insert into question (cust_id,user_id,question_title,question_content,oper_timt,add_date,is_close) values('" + paramString5 + "','" + paramString6 + "','" + paramString2 + "','" + paramString4 + "',now(),now(),'1')";
    if ((paramString1.equals("answer")) && (!paramString3.equals("")))
      str1 = "insert into answer (cust_id,urser_id,question_id,answer_title,answer_content,add_time,is_number) values('" + paramString5 + "','" + paramString6 + "','" + paramString3 + "','" + paramString2 + "','" + paramString4 + "',now(),'1')";
    System.out.print("\n增加问题的sql语句是" + str1 + "\n\n");
    try {
		jt.execute(str1);
		return true;
	} catch (DataAccessException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return false;
	}
   
  }
/*
  public String updatequestion(String paramString1, String paramString2)
  {
    String str1 = "";
    String str2 = "true";
    if ((paramString2.equals("shutdown")) && (!paramString1.equals("")))
      str1 = str1 + "update question set is_close= 0 where question_id='" + paramString1 + "'";
    System.out.print("\n修改问题的sql语句是" + str1 + "\n\n");
    boolean bool = new JDBCExceute().excuteupdate(str1);
    if (bool)
      return str2;
    return "false";
  }

  public ArrayList getQuestionList(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6, String paramString7)
  {
    String str = "";
    if (paramString1.equals("question"))
      if (paramString5.equals("getanswer"))
      {
        str = "select a.add_time,a.cust_id, q.question_title,a.answer_content,q.question_content,q.question_id,q.oper_timt,q.cust_id from question q  inner join answer a on q.question_id=a.question_id where q.is_close = 1 and q.question_id='" + paramString3 + "'";
      }
      else if (paramString5.equals("getanswerall"))
      {
        String localObject = "select question_id from answer where question_id='" + paramString3 + "'";
        ArrayList localArrayList = new JDBCExceute().excute(localObject);
        if (localArrayList.equals(""))
          str = "select '' add_time,'' cust_id, q.question_title,'' answer_content,q.question_content,q.question_id,q.oper_timt,q.cust_id from question q  where q.question_id='" + paramString3 + "' order by q.add_date desc";
        else
          str = "select a.add_time,a.cust_id, q.question_title,a.answer_content,q.question_content,q.question_id,q.oper_timt,q.cust_id from question q  inner join answer a on q.question_id=a.question_id where q.question_id='" + paramString3 + "' order by q.add_date desc";
      }
      else if (paramString5.equals("closed"))
      {
        str = "select question_title,question_content,question_id,oper_timt,cust_id from question where is_close = 0 order by add_date desc";
      }
      else
      {
        str = "select question_title,question_content,question_id,oper_timt,cust_id,is_close from question where 1=1 and is_close = 1";
        if (paramString5.equals("all"))
          str = str.replaceAll("and is_close = 1", "");
        if (!paramString3.equals(""))
          str = str + " and question_id = '" + paramString3 + "'";
        if (!paramString4.equals(""))
          str = str + " and cust_id = '" + paramString4 + "'";
        if (!paramString2.equals(""))
          str = str + " and question_title like '%" + paramString2 + "%'";
        str = str + " order by add_date desc";
        if ((!paramString7.equals("")) && (!paramString6.equals("")))
          str = str + " limit " + (Integer.parseInt(paramString6) - 1) * Integer.parseInt(paramString7) + "," + paramString7;
      }
    if (paramString1.equals("answer"));
    System.out.print("\n问答查询的sql语句是" + str + "\n\n");
    Object localObject = new JDBCExceute().excute(str);
    return (ArrayList)localObject;
  }

  public int getQuestioncount(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5)
  {
    String str1 = "";
    if (paramString1.equals("question"))
      if (paramString5.equals("getanswer"))
      {
        str1 = "select count(q.question_id) count from question q  inner join answer a on q.question_id=a.question_id where q.is_close = 1 and q.question_id='" + paramString3 + "'";
      }
      else if (paramString5.equals("getanswerall"))
      {
        str1 = "select count(q.question_id) count from question q  inner join answer a on q.question_id=a.question_id where q.is_close = 0 and q.question_id='" + paramString3 + "'";
      }
      else if (paramString5.equals("closed"))
      {
        str1 = "select count(question_id) count from question where is_close = 0";
      }
      else
      {
        str1 = "select count(question_id) count from question where 1=1 and is_close = 1";
        if (paramString5.equals("all"))
          str1 = str1.replaceAll("and is_close = 1", "");
        if (!paramString3.equals(""))
          str1 = str1 + " and question_id = '" + paramString3 + "'";
        if (!paramString4.equals(""))
          str1 = str1 + " and cust_id = '" + paramString4 + "'";
        if (!paramString2.equals(""))
          str1 = str1 + " and question_title like '%" + paramString2 + "%'";
        str1 = str1 + " order by add_date desc";
      }
    if (paramString1.equals("answer"));
    System.out.print("\n问答查询数量的sql语句是" + str1 + "\n\n");
    ArrayList localArrayList = new JDBCExceute().excute(str1);
    String str2 = "";
    if ((localArrayList != null) && (localArrayList.size() > 0))
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      if (localHashMap.get("count") != null)
        str2 = localHashMap.get("count").toString();
    }
    return Integer.parseInt(str2);
  }

  public String getcust_nameBycust_id(String paramString)
  {
    String str1 = "";
    String str2 = "";
    if (!paramString.equals(""))
      str1 = "select cust_name from company where cust_id = '" + paramString + "'";
    else
      return str2;
    ArrayList localArrayList = new JDBCExceute().excute(str1);
    if ((localArrayList != null) && (localArrayList.size() > 0))
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      if (localHashMap.get("cust_name") != null)
        str2 = localHashMap.get("cust_name").toString();
    }
    return str2;
  }

  public ArrayList getCompanyList()
  {
    String str = "select cust_name,left(add_date,10) from company_dt where validity =1 limit 0,20";
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }

  public ArrayList getCompanyInfo(String paramString)
  {
    String str = "select c.logo_img,c.cust_name,c.company_scope,ui.msn,ui.email,c.company_address,c.group_contact_phone,c.website, c.cust_supply from company c inner join user_info ui on ui.cust_id=c.cust_id where c.cust_id = '" + paramString + "'";
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }

  public ArrayList getProductByCustId(String paramString)
  {
    String str = "select p.class_id,p.moneytype,p.attach_id,p.product_id,p.product_name,p.small_img,p.product_price,p.product_unit from product p inner join company c on c.cust_id=p.cust_id inner join product_class pc on pc.class_id=p.class_id where c.cust_id = '" + paramString + "'";
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }

  public ArrayList getExtnewsByClassId(String paramString1, String paramString2, String paramString3)
  {
    String str = "select e.title,e.class_id,e.extnews_id,ec.store_path,ec.article_rule,pc.class_name from extnews e inner join extnews_class ec on e.class_id=ec.class_id inner join product_class pc on e.extnews_root_id=pc.class_id where e.extnews_root_id like '" + paramString1 + "%' and e.extnews_root_type='" + paramString2 + "' and e.model='" + paramString3 + "' and  e.remove_tag=1 and e.info_state = 1 order by  e.oper_time desc";
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }

  public String getWordBook(String paramString1, String paramString2)
  {
    if (paramString1.equals(""))
      return "";
    ArrayList localArrayList = new JDBCExceuteThread().excute("select param_name from data_parameter where param_value =" + paramString1 + " and category_code='" + paramString2 + "'");
    if ((localArrayList != null) && (localArrayList.size() > 0))
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      return localHashMap.get("param_name").toString();
    }
    return "";
  }

  public int getNumber(String paramString1, String paramString2)
  {
    String str = "";
    if (paramString1.equals(""))
      return 0;
    if (paramString2.indexOf("recommended") > -1)
    {
      paramString2 = paramString2.replace("recommended", "");
      str = "select count(b." + paramString1 + "_id) countnumber from " + paramString1 + " b inner join " + paramString1 + "_class bc on b.class_id = bc.class_id where b.display_start_date <= now() and b.display_end_date >= now() and validity = 1 and display=1 and b.commend=1 and  bc.dyna_show=1 and b.class_id like '" + paramString2 + "%'";
    }
    else
    {
      str = "select count(b." + paramString1 + "_id) countnumber from " + paramString1 + " b inner join " + paramString1 + "_class bc on b.class_id = bc.class_id where b.display_start_date <= now() and b.display_end_date >= now() and validity = 1 and display=1  and  bc.dyna_show=1 and b.class_id like '" + paramString2 + "%'";
    }
    if (paramString1.equals("buying"))
      str = str.replaceAll("display_", "");
    ArrayList localArrayList = new JDBCExceuteThread().excute(str);
    if ((localArrayList != null) && (localArrayList.size() > 0))
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      return Integer.parseInt(localHashMap.get("countnumber").toString());
    }
    return 0;
  }

  public ArrayList getCompanyList(String paramString)
  {
    String str = "select cust_name,cust_supply,cust_id from company where display=1 and cust_state =1 and cust_type!='0' and cust_supply like '" + paramString + "%' order by add_date desc";
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }
  
  public ArrayList getCompanyList(int start,int size)
  {
    String str = "select cust_name,cust_supply,cust_id from company where display=1 and cust_state =1 and cust_type!='0' order by add_date desc limit "+start+","+size;
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }

  public ArrayList getShangjiList(String paramString)
  {
    String str = "select title,extnews_root_id,extnews_id,class_id from extnews where remove_tag=1 and info_state = 1 and extnews_root_id like '" + paramString + "%'";
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }

  public ArrayList getShangjiList(String paramString1, String paramString2, String paramString3)
  {
    String str = "select '供应' type,product_abstract content,small_img img_url,sales_id id,title,class_id ,left(oper_time,10) publish_date ,cust_id from sales where display_start_date <= now() and display_end_date >= now() and validity = 1 order by oper_time desc  ";
    if (paramString1.equals("buying"))
      str = "select buying_desc content,'求购' type,a.file_path img_url, buying_name title,class_id ,left(oper_time,10) publish_date ,b.cust_id from buying b left join attach a on a.attach_root_id=b.attach_id  where b.start_date <=now() and b.end_date >=now() and b.display=1 and b.validity =1 order by oper_time desc";
    if (paramString1.equals("sales"))
      str = " select product_abstract content, '供应' type,small_img img_url,sales_id id,title,class_id ,left(oper_time,10) publish_date ,cust_id from sales where display_start_date <= now() and display_end_date >= now() and validity = 1 order by oper_time desc";
    if (paramString1.equals("daili"))
      str = "select content,'代理' type,a.file_path img_url,n.extnews_id id,n.title,n.class_id ,left(n.oper_time,10) publish_date,n.cust_id from extnews n left join attach a on n.attach_id=a.attach_id where  n.info_state = 1 and class_id like '100001%' order by oper_time desc";
    if (paramString1.equals("jiameng"))
      str = "select content,'招商' type,a.file_path img_url,n.extnews_id id,n.title,n.class_id ,left(n.oper_time,10) publish_date,n.cust_id from extnews n left join attach a on n.attach_id=a.attach_id where n.info_state = 1 and class_id like '100000%' order by oper_time desc";
    if ((!paramString3.equals("")) && (!paramString2.equals("")))
      str = str + " limit " + (Integer.parseInt(paramString2) - 1) * Integer.parseInt(paramString3) + "," + paramString3;
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }

  public static void main(String[] paramArrayOfString)
  {
  }

  public int getShangjiListCounter(String paramString)
  {
    String str = " select count(sales_id) countnumber from sales where display_start_date <= now() and display_end_date >= now() and validity = 1 order by oper_time";
    if (paramString.equals("buying"))
      str = "select count(b.buying_id) countnumber from buying b left join attach a on a.attach_id=b.attach_id  where b.start_date <=now() and b.end_date >=now() and b.display=1 and b.validity =1 order by oper_time";
    if (paramString.equals("sales"))
      str = " select count(sales_id) countnumber from sales where display_start_date <= now() and display_end_date >= now() and validity = 1 order by oper_time";
    if (paramString.equals("daili"))
      str = "select count(n.extnews_id) countnumber  from extnews n left join attach a on n.attach_id=a.attach_id where   n.info_state = 1 and class_id like '100001%' order by oper_time";
    if (paramString.equals("jiameng"))
      str = "select count(n.extnews_id) countnumber from extnews n left join attach a on n.attach_id=a.attach_id where n.info_state = 1 and class_id like '100000%' order by oper_time";
    ArrayList localArrayList = new JDBCExceute().excute(str);
    if ((localArrayList != null) && (localArrayList.size() > 0))
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      return Integer.parseInt(localHashMap.get("countnumber").toString());
    }
    return 0;
  }

  public ArrayList getAd(String tradeId)
  {
    String str = "select ad.adv_title,ad.adv_content,ad.adv_url from advertisement ad inner join  adv_site advs on ad.adv_id=advs.trade_id where ad.state_date <=now() and ad.adv_state =1 and advs.trade_id='" + tradeId + "' order by ad.oper_time desc limit 0,1";
    ArrayList localArrayList = new JDBCExceute().excute(str);
    return localArrayList;
  }*/
}

